$(document).ready(function() {
	initProduct();
	shopCart.loadCookie();
})
//绑定点击事件
function initProduct() {
	$(".addToCart").bind("click", shopCart.clickAddProduct);
}

//提交订单后执行的方法
function reloadShopCart() {
	shopCart.loadCookie();
	shopCart.showStoreHtml();
}



//===========以下为测试js代码
function callByChild(){
	alert("callByChild")
}
function initCookie() {
	var date = new Date();
	var expireDays = 30;
	date.setTime(date.getTime() + expireDays * 24 * 3600 * 1000);
	alert(document.cookie)
}

function showCookieData() {
	var strCookie = document.cookie;
	alert(strCookie)
	var arrayCookie = strCookie.split(";");
	for(var i = 0; i < arrayCookie.length; i++) {
		//alert(arrayCookie[i]);
		//格式为（product_id=piece)
	}
}

function deleteProductFromCookie(product) {
	var date = new Date();
	date.setTime(date.getTime() - 24 * 3600 * 1000);
	var cookieString = "product" + escape(product.id) + "=" + product.piece
	document.cookie = cookieString + date.toGMTString();
	alert("删除成功!");
}

//新增保存到cookie中 格式为（id，数量）
function addProductToCookie(product, expireHours) {
	var cookieString = "product" + escape(product.id) + "=" + product.piece
	if(expireHours > 0) {
		var date = new Date();
		date.setTime(date.getTime() + expireHours * 3600 * 1000);
		cookieString = cookieString + "; expires=" + date.toGMTString();
	}
	document.cookie = cookieString;
}